//
//  ViewController.m
//  06-UINavgationController
//
//  Created by QC.L on 16/7/21.
//  Copyright © 2016年 QC.L. All rights reserved.
//

#import "ViewController.h"
#import "PushViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor redColor];
    // 设置navgationBar的属性
    // 1.title 标题, 告诉用户, 我这个视图控制器干啥用的
    self.title = @"我是标题, 呵呵呵";
    self.navigationItem.title = @"XXXX, 呵呵呵";
    // 2.titleView 标题视图
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"韩旭", @"王煌"]];
    segment.frame = CGRectMake(100, 100, 150, 44);
    // 标题视图, 修改x, y对视图本身位置没有影响
    self.navigationItem.titleView = segment;
    // 3.leftBarButtonItem
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    // 4.rightBarButtonItem
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(add:)];
    // 5.leftBarButtonItems 数组
    UIBarButtonItem *barButtonItemTitle = [[UIBarButtonItem alloc] initWithTitle:@"XXX" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    UIBarButtonItem *barButtonItemSystemItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(add:)];
    self.navigationItem.leftBarButtonItems = @[barButtonItemTitle, barButtonItemSystemItem, barButtonItemSystemItem, barButtonItemSystemItem];
    // 6.rightBarButtonItems 数组
    // barButtonItems数组中放1-2个Item为最优
    // 7.隐藏navgationBar YES 隐藏, NO, 不隐藏 默认为NO
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.hidden = NO;
    // 8.navgationBar背景样式 默认为 Default
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    // 9.navgationBar的背景颜色
//    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    // 10.barTintColor Bar的颜色
//    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    // 11.tintColor Bar上元素的颜色
//    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 12.translucent 管理半透明效果, YES为开启, NO为关闭
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 200, 200);
    button.backgroundColor = [UIColor blueColor];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    // iOS7以后 默认为YES iOS6包括以前都是NO
    // 设置为YES时, self.view坐标系从原点开始
    // 设置为NO时, self.view坐标系从navgationBar下开始
    self.navigationController.navigationBar.translucent = NO;
    // 13.改变坐标效果, 与translucent为NO时效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;

    // 页面跳转相关
    // 1.push 入栈 pushViewController
    // 2.pop 出栈 popViewControllerAnimated
    // 3.viewControllers存放navgationController里所有的控制器
    // 4.topViewController 栈顶视图控制器 (最后入栈的)
    // 5.visibleViewController 可见视图控制器 (当前显示的)
}

- (void)buttonClicked:(UIButton *)button {
    // 将视图控制器入栈
    [self.navigationController pushViewController:[[PushViewController alloc] init] animated:YES];
}

- (void)comeBack:(UIBarButtonItem *)barButtonItem {
    NSLog(@"返回");
}

- (void)add:(UIBarButtonItem *)barButtonItem {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
